<?php

namespace Admin\Controller;

/** 
 * 举报管理
 * @author Legend. <xcx_legender@qq.com>
 * @param 
 * @return 
 */

class AccuseController extends BaseManageController {


	protected $modelName = 'Common/Accuse';		// 必须定义
	protected $is_del 	 = false; 		// 是否真实删除

	protected function _initialize()
	{
		parent::_initialize();
		$this->text_map['module'] = array(
			'comments' => '评论',
		);
		$this->text_map['status'] = array(
			 0 => '未处理', '1' => '已处理', '-1' => '不予处理'
		);
		$this->assign('options', $this->text_map);
	}


	/** 
	 * 在获取列表前执行 搜索条件
	 * @author Legend. <xcx_legender@qq.com>
	 * @param 
	 * @return 
	 */
	
	public function _before_index()
	{
		$map = array();
        $map['status']  = array('egt',0);
       	$map['module']  = I('module', 'comments', 'trim');
       	$this->assign('module_title', $this->text_map['module'][$map['module']]);
        $this->where = $map;
	}

	/** 
	 * 格式化处理lists内容  可控制获取更多信息  在index里执行
	 * @author Legend. <xcx_legender@qq.com>
	 * @param 
	 * @return 
	 */
	
	public function format_lists(&$lists)
	{
		foreach ($lists as $key => &$item) {
			switch ($item['module']) {
				case 'comments':
					$cService = D('Common/Comments', 'Service');
					$map = array('id' => $item['target_id']);
					$res = $cService->where($map)->find();
					$item['title'] = $res['content'];
					break;
				case 'user':
				#TODO
				break;
				case 'video':
				#TODO
				break;	
				default:
					break;
			}
		}
	}


	/** 
	 * 处理过程  采用并且删除相应的对象
	 * @author Legend. <xcx_legender@qq.com>
	 * @param 
	 * @return 
	 */
	
	public function accept()
	{
		$id = I('id', 0, 'intval');
		$map['id'] = $id;
		$res = $id ? $this->model->where($map)->find() : null;
		$res || $this->error('信息不存在!');
		switch ($res['module']) {
			case 'comments':
				$cService = D('Common/Comments', 'Service');
				$del['id'] = $res['target_id'];
				$done = $cService->where($del)->setField('status', -1);
				break;
			case 'user': break;		// #TODO
			case 'video': break;	// #TODO
			default:
				break;
		}
		if ($done)
		{
			$save['status'] = 1;
			$this->model->where($map)->setField($save);
			$this->success('操作成功!');
		}
		else
		{
			$this->error('对象信息错误, 请不予处理该信息!');
		}
	}

}